Pearson Edexcel · A-Level · Mathematics

    Course version: 603/1499/0 · Version from Sept 2017

    Decision Mathematics 1

    Full specification wording

    Algorithms on graphs - Paper 3D: Decision Mathematics 1: 2.2 Dijkstra’s and Floyd’s algorithm for finding the shortest path.

    Dijkstra's algorithm finds the shortest path from one start vertex to all others in a graph with non-negative weights.

    • Point 2 of 2

    Study notes

    From the teaching notes for this specification point.

    The idea

    Dijkstra's algorithm finds the shortest path from one start vertex to all others in a graph with non-negative weights. Label the start with 0 and the rest with infinity, then repeatedly select the unvisited vertex with the smallest label, make it permanent, and update the labels of its neighbours by adding the edge weight. Record each vertex's predecessor to reconstruct the route. Floyd's algorithm finds shortest paths between every pair of vertices by building a distance matrix and, for each intermediate vertex k, replacing entry d(i,j) with the smaller of d(i,j) and d(i,k)+d(k,j). Both methods require careful bookkeeping, and the final labels or matrix entries give the shortest distances, with routes recovered from predecessors or recorded paths.

    What earns the marks

    • Initialises the start label to zero and all other temporary labels to infinity before beginning Dijkstra's algorithm.
    • Updates a neighbour's label only when the current vertex's permanent label plus the edge weight is smaller than the existing label.
    • Records predecessor vertices so that the shortest route can be traced back from the destination to the start.
    • Applies Floyd's algorithm by comparing d(i,j) with d(i,k)+d(k,j) for each intermediate vertex k and keeping the smaller value.

    Common mistakes and how to put them right

    • Updates a label after the vertex has been made permanent.

      Put it right: Only change temporary labels of unvisited vertices.

    • Compares candidate routes using the wrong sum in Floyd's algorithm.

      Put it right: Add d(i,k) and d(k,j) before comparing with d(i,j).

    • Gives only the shortest distance without the route.

      Put it right: Trace back through predecessors to state the path.

    • Applies Dijkstra's algorithm to a graph with negative weights.

      Put it right: Use Floyd's algorithm or another suitable method instead.

    Exam tips

    • Show the label at each vertex after each iteration in a table so the order of permanence is visible.
    • Box each permanent label and note the vertex order of selection.
    • For Floyd, work one intermediate vertex at a time and show the updated matrix after each k.

    Try the lesson

    The start of the Algorithms on graphs - Paper 3D: Decision Mathematics 1: 2.2 Dijkstra’s and Floyd’s algorithm for finding the shortest path. lesson, made from teaching notes for this specification point.

    Have a go first

    Dijkstra's algorithm is being used to find the shortest path from a start vertex to every other vertex in a network. At one stage, the unvisited vertices have temporary labels 7, 9 and 12, and the visited vertex most recently given a permanent label is A. What is the next step of the algorithm?

    There is more to this lesson

    The full lesson goes on to check your understanding and help you earn the marks. Create a free account to carry on, with your progress saved.

    Carry on with the full lesson

    5 free practice questions every day · Free forever · No card required

    Test your understanding of Algorithms on graphs - Paper 3D: Decision Mathematics 1: 2.2 Dijkstra’s and Floyd’s algorithm for finding the shortest path.

    Active recall beats re-reading. Take an instant quiz now to test what you’ve learned and lock it into long-term memory.

    Take topic quiz

    5 free practice questions every day · Free forever · No card required